The tasks presented were to: design an Arduino circuits board set in accordance with a:

- Light Sensor
- an LED (used RGB LED)
- Temperature Sensor
- Combination of aforementioned and PWM pins
- It's proper (code) execution

Eventually, I created a system which would affect an RGB LED based on the light level and room temperature




Throughout the construction of the board, there were a few minor challenges that I could not overcome without seeking additional feedback. At first, the light sensor was a little tricky to get up and running. It seems that the problem was based in my code, however a few tiny fixes implemented and suddenly it could detect incoming light quite nicely. Piece of cake.

The other larger piece was not quite. It was a simple task of getting the diode to light up brighter once any came bestowing upon my precious little photosensitive resistor. The only thing I managed to do, was to get it on or off with a simple conditional statement embedded. And I quadruple-checked my code, everything seemed fine. I used a different diode, as one just simply would not light up (probably died). I tried doing it with my RGB LED, but it would not budge either for some unforeseen and yet to be studied reason. Eventually, it turned out that, well, Arduino has these PWM pins, which allow the circuit board to provide, well, a more varied output? Which was quite some news to me, as I have never before, for some reason, came across the matter in question.



It should be remarked, that I managed to successfully complete the Lab tutorial, as the light sensor worked, in conjunction with the diode and LED altogether and the temperature sensor properly addressing the room’s temperature with a variety of values. I also connected the Arduino sketch with a Processing sketch and it worked well.

One surprising thing with the temperature sensor was getting it to properly address the room’s temperature, which it would, although by the provision of slightly decreased values. Once I plugged the battery in, the voltage kicked in by that remaining slight amount and the temperature increased from eerie 20 degrees to 22-23 degrees. Interesting, is the usb not good enough to power all the stuff that I chucked onboard?



The only thing that did not go well was me not being able to come up with an interesting combination of the light sensor, diode, temperature sensor and PWM… I mean, what do I do with the temperature sensor, eh? So that’s yet to be sorted

In addition, firmata is still a bit of a riddle. On one hand it is handy, on the other: libraries might refuse working with it, finding workarounds might just not be a good idea, taking an exponential amount of time


//Arduino Code

#include 
#include 
#include 
#include 
#include 
#include 
#include 

/*
SparkFun Inventor’s Kit
Circuit 1C-Photoresistor

Use a photoresistor to monitor how bright a room is, and turn an LED on when it gets dark.

This sketch was written by SparkFun Electronics, with lots of help from the Arduino community.
This code is completely free for any use.

View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-experiment-guide---v40
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
*/

int redPin = 9;
int bluePin = 10;
int greenPin = 11;

int photoresistor = 0;              //this variable will hold a value based on the position of the knob
int threshold = 750;                //if the photoresistor reading is below this value the light will turn on
int calibratedlightlevel;
int lightLevel;
int sensorPin = 0;
int minThreshold = 1023;
int maxThreshold = 0;
const int temperaturePin = A1;
float getVoltage(int pin);
int degreesC;
int degreesF;
int reservedPin = 13;

void setup()
{
  Serial.begin(115200);               //start a serial connection with the computer

  pinMode(6, OUTPUT);              //set pin 13 as an output that can be set to HIGH or LOW

  
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(greenPin, OUTPUT);

}

void loop()
{

    setColor(255,255,255);
  
float voltage, degreeC, degreeF;
voltage = getVoltage(temperaturePin);
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0 / 5.0) + 32.0;

  Serial.print("voltage: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.println(degreesF);
  delay(000);
  
  
  lightLevel = analogRead(sensorPin);
  calibratedlightlevel = map(lightLevel, 100, 1023, 0, 255);
  //read the position of the knob
  photoresistor = analogRead(A0);   //set photoresistor to a number between 0 and 1023 based on how far the knob is turned
  Serial.println(constrain(calibratedlightlevel,0,255));    //print the value of photoresistor in the serial monitor on the computer


    analogWrite(6, constrain(calibratedlightlevel,0,255));         // Turn on the LED  


  delay(100);                       //short delay to make the printout easier to read


}

float getVoltage(int pin){
  return(analogRead(pin) * 0.004882814);
}

void autoRange()

{
  if (lightLevel < minThreshold)
  minThreshold = lightLevel;
  if (lightLevel > maxThreshold)
  maxThreshold = lightLevel;
  lightLevel = map(lightLevel, minThreshold, maxThreshold, 0, 15);
  lightLevel = constrain(lightLevel, 0, 255);
}

void setColor(int red, int green, int blue)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}



I feel that the Arduino board and sensor are not that much of a challenge at present time and I am looking forward to actually implementing a bit more elaborate setups. Especially I am curious of how I may connect Arduino with processing via Bluetooth in a rather simple and easy to understand manner. Although, at the same time there are features that pop up and turn out as quite new for me, for instance the PWM stuff, just a few pins available and marked with a ~. Now that’s something unexpected. I even used a few different pins to see whether these were damaged or so, but I didn’t plug it to the PWM ones.

It seems, though, that the problems I have encountered clearly state that working as a group will likely be more efficient, as the problems are what hold projects up in the end. You eventually come to a conclusion of what you want installed and once you actually start introducing the idea, it may turn out that many features just simply do not feel like working. And once they don’t and you have no idea why, you start figuring it out and the entire process will take ages. That’s why collaboration is so important, as the final effect may become sorted much quicker.

Another important lesson, although it wasn’t that much of a major problem in my case, was that some things do break and if they do, you gotta figure this out asap. With simple components like diodes, it won’t be much of an issue, but once some more elaborate equipment gets introduced… Accidents happen, it’d be best to know whether something works or doesn’t and whether it is our fault or not. Nevertheless, getting to know whether a component works or doesn’t is tricky, we take it usually for granted that it actually does. But what if it doesn’t? Do you just stick with trying to plug the component in new ways, rewrite the code or… perhaps it’d be best to check whether it works at someone else’s hands, or if this person’s component actually works?


Not much really, I think I could’ve improved by expanding the idea and just figuring out the PWM much faster. Then I could focus on other stuff, like, maybe expanding the processing sketch or getting some cool Arduino features installed? Or maybe I could have even managed to launch the Bluetooth module at last, with all its functions. Bluetooth serial ain’t a module to joke with ;)


I’m not sure how the temperature sensor could be utilized in any other way then to just simply showcase information for public spaces. Otherwise, it is a bit limited. It could be used creatively, obviously, but still it is not necessarily a sensor that allows one to do that much with.


The photosensitive resistor is a complete different story, although still fairly limited, any changes introduced may be instant. Just make someone for instance limit the light that comes into the sensor and the changes will be showcased on whatever the installation.


I did a few iterations. First of all: if the temperature is below 25 degrees, blueLED will light up. If it's over 25 degrees, redLED will light up. If the detected light surpasses a value of a 100, the greenLED will light up in relation to the detected values (100-255). The video showcasing how it works is at the end of the post, I utilised a RGB LED, temperature sensor, photosensitive resistor, PWM pins and a 8.4V battery